<template>
	<view class="content" v-if="defultBankFlag">
		<view class="header">
			<view class="t">
				<view class="h3">
					我的余额
				</view>
				<view class="p">
					<text>{{user.cash}}</text>
				</view>
			</view>
			<view class="d">
				提现最小金额 <text>¥100</text>
			</view>
		</view>
	<view class="main">
		
			<navigator url="/pages/cashier/chuxu" class="d">
				<view class="l">
					<image :src="defultBank.bank_logo" mode=""></image>
					<view class="bankInfo">
						<view class="h3"  >
							{{defultBank.name?defultBank.name:''}}
						</view>
						<view class="p" v-if="defultBank.full_card_number">
							**** **** ****
							{{defultBank.full_card_number.substring(defultBank.full_card_number.length-4)}}
						</view>
					</view>
				</view>
				<view class="r">
					<u-icon name="arrow-right"></u-icon>
				</view>
			</navigator>
			<view class="t">
				<view class="title">
					提现金额
				</view>
			</view>
			<view class="input">
				¥ <input type="text" v-model="amount" value="" placeholder="请输入收款金额" />
				<view class="span" @click="allAmount()">
					全部提款
				</view>
			</view>
			<view class="btn" @click="submit">
				提现
			</view>
		</view>
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				defultBankFlag:false,
				user:{},
				defultBank:{},
				amount:'',
			}
		},
		onLoad(){
			let that = this;
			this.$u.api.userInfoByToken({}).then(res => {
				that.user = res
				uni.setStorageSync('user_info', JSON.stringify(res));
				this.getBankList();
			})
			
		},
		onShow() {
		uni.$on('bankInfo', (bankInfo) => {
			this.defultBank = bankInfo.addrsssid
			this.defultBankFlag = true
		})	
		},
		methods: {
			getBankList(){
				this.$u.api.bankcard({
					page:1,
					page_size:20,
					type:'00'
				}).then(res => {
						this.defultBank = res.list[0];
						this.defultBankFlag = true
				})
			},
			allAmount(){
				console.log(222)
				this.amount = this.user.cash
			},
			submit(){
				    var regPos = /^\d+(\.\d+)?$/; //非负浮点数
					if(regPos.test(this.amount) && this.amount*1>0){
						let params={
							amount:this.amount,
							bankcard_id:this.defultBank.id
						}
						this.$u.api.userCasht(params).then(res=>{
							console.log(res)
							uni.navigateTo({
								url:'/pages/center/withdrawalLog'
							})
						})
						
				    }else{
				        uni.showToast({
				        	title:'请输入正确金额',
				        	icon:'none'
				        })
				        return
				    }
				
				
				
				
			}
		}
	}
</script>
<style>
	page {
		background-color: #f4f5f7;
	}
</style>
<style scoped lang="scss">
	.header {
		width: 696rpx;
		height: 218rpx;
		background-color: #4993ec;
		margin: 27rpx auto;
		border-radius: 10rpx;
		box-sizing: border-box;
		padding: 20rpx 25rpx;
		color: #fff;

		flex-direction: column;
		display: flex;
		justify-content: space-between;

		text {
			font-weight: bold;
		}

	}
	.main {
		background-color: #fff;
		margin: 20rpx 0;
		padding: 0 30rpx;
		padding-bottom: 30rpx;
	
		.t {
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 100rpx;
			font-size: 32rpx;
			color: #8e8e8e;
	
			.jilu {
				color: #ec6a38;
				font-size: 28rpx;
			}
		}
	
		.d {
			padding: 30rpx 0;
			border-bottom: 1px solid #eee;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 30rpx;
	
			image {
				width: 90rpx;
				height: 90rpx;
				border-radius: 100%;
				margin-right: 15rpx;
				margin-top: -5rpx;
			}
	
			.l {
				display: flex;
				align-items: center;
	
				.h3 {
					margin-bottom: 5rpx;
					margin-top: 5rpx;
				}
			}
		}
	}
	
	.input {
		padding-bottom: 30rpx;
		border-bottom: 1px solid #eee;
		display: flex;
		align-items: center;
		font-size: 35rpx;
	position: relative;
		input {
			margin-left: 10rpx;
			flex: 1;
			font-size: 30rpx;
		}
		.span{
			position: absolute;
			right: 30rpx;
			top: 0;
			color: #4993ec;
			font-size: 30rpx;
			z-index: 9;
		}
	}
	
	.btn {
		width: 100%;
		height: 84rpx;
		color: #fff;
		font-size: 30rpx;
		text-align: center;
		line-height: 84rpx;
		border-radius: 20rpx;
		background-color: #ec6a38;
		margin-top: 50rpx;
	}
</style>
